import { createApp } from 'vue'
import App from './App.vue'
import router from './router/index'
import { store, key } from './store/index'
import ElementPlus from 'element-plus'
import 'element-plus/dist/index.css'
import * as Icons from '@element-plus/icons-vue'
import { useAutoLogin } from '@/composables/login/useLogin'
import { useRouter } from 'vue-router'
const app = createApp(App)
app.use(router)
    .use(store, key)
    .use(ElementPlus)
    .mount('#app')

Object.keys(Icons).forEach((key) => {
    app.component(key, Icons[key as keyof typeof Icons])
})

router.beforeEach(async(to, from, next) => {
    if (to.path === '/login') {
        let token = localStorage.getItem('token')
        const { autoLogin } = useAutoLogin();
        autoLogin();
        next();
    }
    next();
})